<?php
/**
 * Created by PhpStorm.
 * User: 王
 * Date: 2016/10/26
 * Time: 18:11
 */

namespace app\components\behaviors;

use Yii;
use yii\base\Behavior;
use yii\db\ActiveRecord;

class CreatorBehaviors extends  Behavior
{
    public $fieldName;

    public function events()
    {
        return [
            ActiveRecord::EVENT_BEFORE_INSERT => "setValue",
        ];
    }

    /**
     *设置用户的属性等于登陆的id
     */
    public function setValue()
    {
        $this->owner->{$this->fieldName} = Yii::$app->user->id;


    }
}